#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
int searchInsert(int* nums, int numsSize, int target) {
    int left = 0;
    int right = numsSize - 1;
    int mid;
    while (left < right)
    {
        mid = (left + right) / 2;
        if (nums[mid] < target)
        {
            left = mid;
        }
        else if (nums[mid] > target)
        {
            right = mid;
        }
        else
        {
            return mid;
        }
    }
    return left;
}


char* compressString(char* S) {
    char* tile = (char*)malloc((sizeof(S) * 2));
    char* ret = tile;
    char* fast = S + 1;
    char* det = S;
    while (*det)
    {
        int sum = 1;
        if (*fast == *det)
        {
            *tile++ = *det;
            while (*fast == *det)
            {
                sum++;
                fast++;
            }
            if (sum >= 10 && sum < 100)
            {
                *tile++ = sum / 10 + '0';
                *tile++ = sum % 10 + '0';

            }
            else if (sum >= 100 && sum < 1000)
            {
                *tile++ = sum / 100 + '0';
                *tile++ = sum % 100 / 10 + '0';
                *tile++ = sum % 10 + '0';
            }
            else if (sum >= 1000 && sum < 10000)
            {
                *tile++ = sum / 1000 + '0';
                *tile++ = sum % 1000 / 100 + '0';
                *tile++ = sum % 100 / 10 + '0';
                *tile++ = sum % 10 + '0';
            }
            else if (sum >= 10000 && sum < 100000)
            {
                *tile++ = sum / 10000 + '0';
                *tile++ = sum % 10000 / 1000 + '0';
                *tile++ = sum % 1000 / 100 + '0';
                *tile++ = sum % 100 / 10 + '0';
                *tile++ = sum % 10 + '0';
            }
            else
            {
                *tile++ = sum + '0';
            }
            det = fast;
            fast = det + 1;
        }
        else
        {
            *tile++ = *det++;
            *tile++ = '1';
            
            if (*fast)
                fast++;
        }

    }
    *tile = '\0';
    if (strlen(ret) >= strlen(S))
        return S;
    return ret;
}

void test()
{
    int a[3] = {  0};
    int c = searchInsert(a, 4,5);
    printf("%d", c);
}
void test2()
{
    char a[] = "xxxxSSSXXXXXXXfffffooooojggggguuuuummmvOOOOOOeYYYYYaaaaaavvvZZZZ";
    char* ret = compressString(a);
    puts(ret);
}
int main()
{
	test2();
	return 0;
}